package main

import (
	"github.com/savsgio/atreugo/v11"
	_ "hotter/dbInit"
	"hotter/listeningFile"
	"hotter/middleware"
	"hotter/router"
	"hotter/utils"
	"hotter/variable"
)

//func FindFile(folder string) string {
//	files, _ := ioutil.ReadDir(folder)
//	for _, file := range files {
//		if file.IsDir() {
//			FindFile(folder + "/" + file.Name())
//		} else {
//			fmt.Println(folder + "/" + file.Name())
//
//			return folder + "/" + file.Name()
//		}
//	}
//
//	return "fileName"
//}

func main() {

	if variable.Db != nil {
		db, _ := variable.Db.DB()
		defer db.Close()
	}

	variable.W = utils.NewWorkerNovel()

	go listeningFile.ProcessFile()

	config := atreugo.Config{
		Addr: "0.0.0.0:6364",
	}
	variable.Server = atreugo.New(config)
	variable.Server.UseBefore(middleware.Cors())

	router.NewHotterRouter().RouterInit()

	if err := variable.Server.ListenAndServe(); err != nil {
		panic(err)
	}
}
